<#include "common/common.html"/>
<meta charset="UTF-8">

	<table id="datagrid" class="easyui-datagrid" title="行业数据字典管理" style="width:100%;height:auto"
	        title="行业管理"  
	        toolbar="#searchtool,#toolbar" 
            pagination="true"
            rownumbers="true" 
            fitColumns="true"
            url="${base}/industry/queryList"
			data-options="
				iconCls: 'icon-edit',
				toolbar: '#toolbar',
				pageSize:20,pageList:[5,10,15,20],
				onClickCell: onClickCell
			">
		<thead>
			<tr> 
			    <th data-options="field:'id',width:100,checkbox:true">序号</th>
			    <th data-options="field:'squences',width:100,editor:'textbox'">排序</th>
			    <th data-options="field:'color',width:100,editor:'textbox'">色值</th>
				<th data-options="field:'industryName',width:100,editor:'textbox'">行业名称</th>
				<th data-options="field:'ishidden',width:100" formatter="formateOpe">是否隐藏</th>
                <th data-options="field:'updateTime',width:100">更新时间</th>
				
			</tr>
		</thead>
	</table>
    <div id="searchtool" style="padding:5px">    
      <span>行业名称:</span><input type="text" id="industryName" value="" size=30 />  
      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="javascript:queryDataIndustry('industry/queryList');">搜索</a>  
    </div> 
	<div id="toolbar" style="height:auto">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:openNewDlg('行业添加','industry/save','industryType-dlg','industryType-fm');">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="javascript:multiUpdatePosit('industry/edit')">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="javascript:updateStatus('批量显示',1);">批量显示</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:updateStatus('批量隐藏',0);">批量隐藏</a>
	</div>
	<div id="industryType-dlg" class="easyui-dialog"  style="padding:10px 20px" closed="true" buttons="#dlg-buttons">
        <form id="industryType-fm" method="post">
            <div class="fitem">
                <label>行业名称:</label>
                <input name="industryName" class="easyui-textbox" required="true">
            </div>
             <div class="fitem">
                <label>排序:</label>
                <input name="squences" class="easyui-textbox" >
            </div>
             <div class="fitem">
                <label>色值:</label>
                <input name="color" class="easyui-textbox" required="true">
            </div>
        </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" id="saveBtn" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="javascript:submitIndustry('industryType-dlg','industryType-fm')" style="width:90px">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#industryType-dlg').dialog('close')" style="width:90px">取消</a>
</div>
	
	<script type="text/javascript">
/*  		var editIndex = undefined;
		function endEditing(){
			if (editIndex == undefined){return true}
			if ($('#datagrid').datagrid('validateRow', editIndex)){
				var ed = $('#datagrid').datagrid('getEditor', {index:editIndex,field:'names'});
				var productname = $(ed.target).combobox('getText'); //获得修改的列名称
				//var rows = $('#datagrid').datagrid('getChanges');
				var rows = $('#datagrid').datagrid('getSelections');
				var positionsTypeId 
				for(var i=0; i<rows.length; i++){
					positionsTypeId = rows[i].id;
					if(null!=positionsTypeId && positionsTypeId!=""){
						saveData(positionsTypeId,productname);
					}
		    	}
				$('#datagrid').datagrid('getRows')[editIndex]['names'] = productname;
				$('#datagrid').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
		}  */
		
		function multiUpdatePosit(actUrl){
			$('#datagrid').datagrid('endEdit', editCellIndex);
			var rows = $('#datagrid').datagrid('getChanges');

		    if (rows.length>0){
		    	var ids = [];
		    	var names = [];
		    	var squs = [];
		    	var colors = [];
		    	for(var i=0; i<rows.length; i++){
		    		ids.push(rows[i].id);
		    		squs.push(rows[i].squences);
		    		var nameValue=rows[i].industryName;

		    		if(!nameValue){
		    			$.messager.alert('提示','名称不能为空','info');
		    			queryDataIndustry();
		    			return;
		    		}
		    		if(nameValue.indexOf(" ")!=-1){
		    			$.messager.alert('提示','名称不能有空格','info');
		    			queryDataIndustry();
		    			return;
		    		}
		    		names.push(nameValue);
		    		
		    		if(!rows[i].color){
		    			$.messager.alert('提示','颜色不能为空','info');
		    			queryDataIndustry();
		    			return;
		    		}
		    		colors.push(rows[i].color);
		    	}
		    	var idsStr= ids.join();
		    	var namesStr = names.join();
	            var squencesStr = squs.join();
	            var colorStr = colors.join();
		    	$.ajax({
		    		url : "${base}/industry/edit",
		    		type : 'post',
		    		data : {
		    			ids:idsStr,
		    			industryNames:namesStr,
		    			squencesStr:squencesStr,
		    			colorStr:colorStr
		    		},
		    		success : function(result) {
		    			result = eval('('+result+')');
	    		           if (result.errorMsg){
	    		        	   $.messager.alert('错误',result.errorMsg,'error');
	    		           } else if(result.infoMsg){
	    		        	   $.messager.alert('提示',result.infoMsg,'info');
	    		        	   queryDataIndustry();
	    		        	   
	    		           }else{
	    		                   $('#datagrid').datagrid('reload');   
	    		               }

		    		}
		    		 });
		    }
		}
		
		function onClickRow(index){
			if (editIndex != index){
				if (endEditing()){
					$('#datagrid').datagrid('selectRow', index)
							.datagrid('beginEdit', index);
					editIndex = index;
				} else {
					$('#datagrid').datagrid('selectRow', editIndex);
				}
			}
		}
		function append(){
			if (endEditing()){
				$('#datagrid').datagrid('appendRow',{status:'P'});
				editIndex = $('#datagrid').datagrid('getRows').length-1;
				$('#datagrid').datagrid('selectRow', editIndex)
						.datagrid('beginEdit', editIndex);
			}
		}
		function removeit(){
			if (editIndex == undefined){return}
			$('#datagrid').datagrid('cancelEdit', editIndex)
					.datagrid('deleteRow', editIndex);
			editIndex = undefined;
		}
		function addPositionsType(url){
			if (endEditing()){
				$('#datagrid').datagrid('acceptChanges');
			}
		}
		function reject(){
			$('#datagrid').datagrid('rejectChanges');
			editIndex = undefined;
		}
		function getChanges(){
			var rows = $('#datagrid').datagrid('getChanges');
			for(var i=0; i<rows.length; i++){
	    		alert("id is:"+rows[i].id);
	    	}
		}
		
		function saveData(id,value) {
			$.ajax({
				url : "${base}/industry/edit",
				type : 'post',
				data : {
					"ids" : id,
					"industryName" : value
				},
				success : function(result) {
                	var result = eval('('+result+')');
                	if (result.errorMsg){
                 	   $.messager.alert('错误',result.errorMsg,'error');
                    } else if(result.infoMsg){
                 	   $.messager.alert('提示',result.infoMsg,'info');
                 	  queryDataIndustry();
                    }else{
                       $('#datagrid').datagrid('reload');   
                    }
				}
			});

		}
		function submitIndustry(dlgId,fmId){
			$("#"+fmId).form('submit',{
		    url: url,
		    onSubmit: function(){
		       return $(this).form('validate');
		    },
		    success: function(result){
		       var result = eval('('+result+')');
		       $("#"+dlgId).dialog('close');   
		           if (result.errorMsg){
		        	   $.messager.alert('错误',result.errorMsg,'error');
		           } else if(result.infoMsg){
		        	   $.messager.alert('提示',result.infoMsg,'info');
		        	   queryDataIndustry();
		        	   
		           }else{
		                   $('#datagrid').datagrid('reload');   
		               }
		                }
		            });
		        }
		

		
		
		function queryDataIndustry(){  
			//var startDate = $("#beginTimes").datetimebox("getValue") ;
			//var titles = encodeURI(encodeURI(login_name));   

			$('#datagrid').datagrid('load',{ 
				industryName:$('#industryName').val(),
			} 
		); 
		}
		
		function formateOpe(val){
			if (val == 1){
				return '显示';
			} else if(val == 0){
				return '隐藏';
			}else {
				return '未知';
			}
		}
		
		function updateStatus(title,status){
			var rows = $('#datagrid').datagrid('getSelections');
		    if (rows.length>0){
		    	var ids = [];
		    	for(var i=0; i<rows.length; i++){
		    		ids.push(rows[i].id);
		    	}
		    	url = $("#base").val()+"/industry/updateStatus?ids="+ids.join(",")+"&status="+status;
		        $.messager.confirm(title,'确定要'+title+'吗?',function(r){
		            if (r){
		                $.post(url,function(result){
		                	var result = eval('('+result+')');
		                	if (result.errorMsg){
		                 	   $.messager.alert('错误',"修改行业状态失败,请稍后再试",'error');
		                 	  queryDataIndustry(); 
		                    } else if(result.infoMsg){
		                 	   $.messager.alert('提示',"修改行业状态成功",'info');
		                 	  queryDataIndustry(); 
		                    }else{
		                       $('#datagrid').datagrid('reload');   
		                    }
		                });
		            }
		        });
		    }else{
		    	 $.messager.alert('提示','请选择一条信息进行操作','info');
		    }
		    queryDataIndustry(); 
		}
		
		
		
	</script>



